package org.ehe.finance.voucher.domain;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.*;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.ehe.common.mybatis.core.domain.BaseEntity2;

import java.math.BigDecimal;
import java.time.LocalDate;

/**
 * 记账凭证主表实体
 * @author :zhangnn
 * @className :ErpFinanceVoucher
 * @description: TODO
 * @date 2025-08-25 09:27:20
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("erp_finance_voucher")
public class ErpFinanceVoucher extends BaseEntity2 {

    @Schema(description = "凭证ID")
    @TableId(value = "id", type = IdType.AUTO)
    private Long id;

    @Schema(description = "凭证号")
    @NotBlank(message = "凭证号不能为空")
    @Size(max = 50, message = "凭证号长度不能超过50个字符")
    private String voucherNo;

    /**
     * 编号
     */
    @NotBlank(message = "编号不能为空")
    private String serialNumber;

    @Schema(description = "凭证类别ID")
    @NotNull(message = "凭证类别不能为空")
    private Long voucherTypeId;

    @Schema(description = "凭证日期")
    @NotNull(message = "凭证日期不能为空")
    private LocalDate voucherDate;

    @Schema(description = "会计期间:YYYY-MM")
    @NotBlank(message = "会计期间不能为空")
    @Pattern(regexp = "^\\d{4}-\\d{2}$", message = "会计期间格式必须为YYYY-MM")
    private String period;

    @Schema(description = "附件张数")
    @Min(value = 0, message = "附件张数不能小于0")
    private Integer attachmentCount = 0;

    @Schema(description = "借方金额合计")
    @NotNull(message = "借方金额合计不能为空")
    @DecimalMin(value = "0.00", message = "借方金额不能小于0")
    @Digits(integer = 16, fraction = 2, message = "借方金额格式不正确")
    private BigDecimal totalDebit = BigDecimal.ZERO;

    @Schema(description = "贷方金额合计")
    @NotNull(message = "贷方金额合计不能为空")
    @DecimalMin(value = "0.00", message = "贷方金额不能小于0")
    @Digits(integer = 16, fraction = 2, message = "贷方金额格式不正确")
    private BigDecimal totalCredit = BigDecimal.ZERO;

    @Schema(description = "摘要")
    @Size(max = 255, message = "摘要长度不能超过255个字符")
    private String abstractInfo;

    @Schema(description = "出纳员ID")
    private Long cashierId;

    @Schema(description = "记账员ID")
    private Long accountantId;

    @Schema(description = "审核员ID")
    private Long reviewerId;

    @Schema(description = "凭证状态:1制单,2审核,3记账,4结账")
    @NotNull(message = "凭证状态不能为空")
    @Min(value = 1, message = "凭证状态值不正确")
    @Max(value = 4, message = "凭证状态值不正确")
    private Integer voucherStatus = 1;

    @Schema(description = "来源类型:1手工录入,2系统生成")
    @Min(value = 1, message = "来源类型值不正确")
    @Max(value = 2, message = "来源类型值不正确")
    private Integer sourceType = 1;

    @Schema(description = "来源单据ID")
    private Long sourceId;

    @Schema(description = "来源单据号")
    @Size(max = 50, message = "来源单据号长度不能超过50个字符")
    private String sourceNo;

    @Schema(description = "创建部门")
    private Long createDept;
}
